//============================================================================
// Name        : Clover_analysis.cpp
// Author      : gabi
// Version     :
// Copyright   : free for all
// Description : Hello World in C, Ansi-style
//============================================================================

#include <iostream>
#include <fstream>
#include "cEventList.hh"
#include "TApplication.h"
#include <stdlib.h>
using namespace std;

int main(int argc, char* argv[]) {

	TApplication theApp("theApp", 0, argv); //line to allow interactive canvas in the program
		// should be uncommented for the root ->Draw() operations to yield visible results while testing stuff. When running the code for production, there is no need to flash the screen on each draw() call.



	cInputInfo info(argc, argv);

	cEventList globalList("FullData");

	//set everything up
	globalList.ReadFromDir(info.dirname,info.cardNo,1);
	globalList.Print();
					globalList.MakeDetectorList();
					globalList.ReadCalibration(info.dirname, info.cardNo);
					globalList.MakeEmptySpectras();

	//run
	int currentFile;
	currentFile=2;
	while(currentFile>0){
		currentFile=globalList.ReadFromDir(info.dirname,info.cardNo, currentFile);

		//cout<<endl<<endl<<globalList<<endl<<endl;

		//cout<<endl<<endl<<currentFile<<endl<<endl;
		globalList.CalibrateEnergy();
		globalList.MakeSpectraSingle();
		globalList.MakeTIDSingle();
		globalList.MakeMatrices();
		globalList.CleanData();
	};
	globalList.WriteResults(info.dirname, info.cardNo);
	globalList.WriteSpectraSingle(info.dirname, info.cardNo);

		//globalList.ReadFromDir(info.dirname);
//		globalList.ReadFromDir(info.dirname,info.cardNo, 2);
//		cout<<"printing"<<endl;
//				globalList.Print();
//				globalList.MakeDetectorList();
//				globalList.ReadCalibration(info.dirname);
//				//exit(1);
//		globalList.MakeSpectraSingle();
//		globalList.WriteSpectraSingle();
//
//		//globalList.MakeSpectraWithPileUp();
//		globalList.MakeTIDSingle();
//		globalList.MakeTIDAll();
//		globalList.MakeMatrices();
	//cout<<"Hello world"<<endl;
	return 1;
}
